//
//  LSZPrayerContentEvaluationVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/12/22.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZPrayerContentEvaluationVC.h"

@interface LSZPrayerContentEvaluationVC ()

@end

@implementation LSZPrayerContentEvaluationVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([self.strtype isEqualToString:@"0"]) {
        self.type = @"6";
    }else{
        self.type = @"7";
    }
    self.page = 1;
    [self initWithPingJia:self.page ];
    [self initClickZan];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    if ([self.justClickBlessing isEqualToString:@"2"]) {
        NSDictionary * dicdgjz = [[NSDictionary alloc]initWithObjectsAndKeys:@(self.lastNumber),@"num", nil];
        NSNotification *notification =[NSNotification notificationWithName:@"dgjz" object:nil userInfo:dicdgjz];//dgjz
        [[NSNotificationCenter defaultCenter] postNotification:notification];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"dgjz" object:nil];
    }
}
#pragma mark - 获取点赞的数据
-(void)initClickZan
{
    [LSZRequestResolutionDic GetThumbUp:self.resource_id type:self.type page:[NSString stringWithFormat:@"%zd",self.page] :^(BOOL isOK, NSString * Str, LSZThumbUpOrBlessingListForResourcesManager * manager) {
        if (isOK == YES) {
            self.zanManager = manager;
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];
            [self.tableViewContentEvaluation reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
            [self DecideIfYouHaveSentBlessing];
        }else{
            [SVProgressHUD showErrorWithStatus:Str];
            [SVProgressHUD dismissWithDelay:1];
        }
    }];
}
#pragma mark - 查询是否送过祝福
-(void)DecideIfYouHaveSentBlessing
{
    NSString * uid  = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"uid"]];
    for ( LSZThumbUpOrBlessingListForResourcesMg * manager in self.zanManager.mutMgArray) {
        NSString * id_id = [NSString stringWithFormat:@"%@",manager.praiserId];
        if ([uid isEqualToString:id_id]) {
            LSZContentTableViewCell * cell = (LSZContentTableViewCell *)[self.tableViewContentEvaluation cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
             cell.butBenediction.backgroundColor = RGBColor(212, 212, 212);
            cell.butBenediction.userInteractionEnabled = NO;
            cell.labelBenediction.text = @"已祝福";
            return;
        }
    }
}
#pragma mark - 获取评价row -1刷新整个区   其他是特定的
-(void)initWithPingJia :(NSInteger)page
{
    [LSZRequestResolutionDic GetTheResourceEvaluationList:self.resource_id type:self.type page:[NSString stringWithFormat:@"%zd",page]  :^(BOOL isOK, NSString * Str, LSZResourceEvaluationListManager * manager) {
        if (isOK == YES) {
            if(self.page == 1){
                [self.arrayMutPingJia removeAllObjects];
                [self.arrayMutPingJia addObjectsFromArray:manager.mutMgArray];
                if (manager.mutMgArray.count == 0) {
                    self.tableViewContentEvaluation.mj_footer.hidden = YES;
                }
            }else{
                if (manager.mutMgArray.count >0) {
                    [self.arrayMutPingJia addObjectsFromArray:manager.mutMgArray];
                  }else{
                      self.page = self.page-1;
                      [self.tableViewContentEvaluation.mj_footer endRefreshingWithNoMoreData];
                }
            }
            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
            [self.tableViewContentEvaluation reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.arrayMutPingJia = [[NSMutableArray alloc]init];
    if ([self.strtype isEqualToString:@"0"]) {
        self.title = @"祷告详情";
    }else{
        self.title = @"见证详情";
    }
    [self.tableViewContentEvaluation setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
    [self.tableViewContentEvaluation registerClass:[LSZContentTableViewCell class] forCellReuseIdentifier:@"LSZContentTableViewCell"];
    [self.tableViewContentEvaluation registerClass:[LSZAppraiseTableViewCell class] forCellReuseIdentifier:@"LSZAppraiseTableViewCell"];
    [self.tableViewContentEvaluation registerClass:[LSZHeaderLabelCell class] forHeaderFooterViewReuseIdentifier:@"LSZHeaderLabelCell"];
    [LSZSpecialPackaging initWithAppraise:self.view share:1 :^(UIView * lowView,UITextView * textView,UILabel * label, UIButton * but, UIImageView * imageView) {
        textView.delegate = self;
        self.lowView = lowView;
        self.textView = textView;
        label.text = @"点击此处说两句....";
        self.uilabel = label;
        [but addTarget:self action:@selector(clickButShare) forControlEvents:UIControlEventTouchUpInside];
    }];
    self.tableViewContentEvaluation.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        self.page = 1;
        //诗歌歌谱的分类
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 刷新表格  和结束刷新
            [self initWithPingJia:self.page];
            [self.tableViewContentEvaluation.mj_header endRefreshing];
        });
    }];
    self.tableViewContentEvaluation.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        self.page++;
        //诗歌歌谱的分类
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 刷新表格  和结束刷新
            [self initWithPingJia:self.page];
            [self.tableViewContentEvaluation.mj_footer endRefreshing];
        });
    }];
    //监听键盘
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    //点击点赞人
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ClickThumbUpPeopleWithDic:) name:@"ClickThumbUpPeople" object:nil];

    UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSingleTap)];
    singleTap.delegate = self;
    [self.view addGestureRecognizer:singleTap];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }
    return  self.arrayMutPingJia.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if(indexPath.row == 0){
            if (ScreenWidth == 320) {
                //5
                CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:13.5 :self.strContent];
                return (height+109+200+30);
            }else if(ScreenWidth == 375){
                // 6 7
                CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:14 :self.strContent];
                return (height+114+220+32);
            }else {
                //plus
                CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:14.5 :self.strContent];
                return (height+119+240+34+10);
            }
        }else{
            CGFloat wids = (ScreenWidth-40)/6;
            if(self.zanManager.mutMgArray.count%6 == 0){
                return  (self.zanManager.mutMgArray.count/6)*(wids+10)+40;//这个要根据个数可变
            }else{
                return  (self.zanManager.mutMgArray.count/6+1)*(wids+10)+40;//这个要根据个数可变
            }
        }
    }else{
        LSZResourceEvaluationListMg * manager = nil;
        manager = self.arrayMutPingJia[indexPath.row];
        CGFloat intFont;
        if (ScreenWidth == 320) {
            //5
            intFont = 13.5;
        }else if(ScreenWidth == 375){
            // 6 7
            intFont = 14;
        }else {
            //plus
            intFont = 14.5;
        }

        CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:intFont :manager.content];
        int count;
        if([NSStr(manager.commentNum) isEqualToString:@"0"]||NSStr(manager.commentNum).length == 0||[NSStr(manager.commentNum) isEqualToString:@""]){
            count  = 0;
        }else{
            count = 1;
        }
        if (ScreenWidth == 320) {
            //5
            return height+56+count*29;
        }else if(ScreenWidth == 375){
            // 6 7
            return height+60+count*32.5;
        }else {
            //plus
            return height+64+count*34;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        if(self.arrayMutPingJia.count>0){
            if (ScreenWidth == 320) {
                //5
                return 35;
            }else if(ScreenWidth == 375){
                // 6 7
                return 40;
            }else {
                //plus
                return 45;
            }
        }else{
            return 0.001;
        }
    }else{
        return 0.0001;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1&&self.arrayMutPingJia.count>0) {
        LSZHeaderLabelCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZHeaderLabelCell"];
        cell.label.text = @"全部评价";
        cell.contentView.backgroundColor =  [UIColor whiteColor];
        return cell;
    }else{
        UITableViewHeaderFooterView * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
        if (!header) {
            header = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"header"];
        }
        return header;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if(indexPath.row == 0){
            LSZContentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZContentTableViewCell" forIndexPath:indexPath];
            [self initWithOneSection:cell indexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            LSZHeaderImageFootCell * cellFoot = [[LSZHeaderImageFootCell alloc]initWithOneFootHeaderImageViewWithManager:self.zanManager];
            cellFoot.backgroundColor =  RGBColor(240, 239, 245);
            cellFoot.selectionStyle = UITableViewCellSelectionStyleNone;
            return cellFoot;
        }
    }else{
        LSZAppraiseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZAppraiseTableViewCell" forIndexPath:indexPath];
        LSZResourceEvaluationListMg * manager = nil;
        manager = self.arrayMutPingJia[indexPath.row];
        cell.ResourceEvaluationListMg = manager;

        __weak typeof(self) weakSelf = self;
        [cell.imageViewHeader tapGesture:^(UIGestureRecognizer *ges) {
            //个人信息页
            LSZPersonalInformationPageVC * vc = [[LSZPersonalInformationPageVC alloc]init];
            vc.uid =manager.publisherId;
            vc.imageViewHeader = manager.publisherHead;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
        cell.butZan.tag = indexPath.row +1;
        [cell.butZan addTarget:self action:@selector(clickZan:) forControlEvents:UIControlEventTouchUpInside];
        UITapGestureRecognizer *tapNumber = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNumber:)];
        [cell.labelZanNumber addGestureRecognizer:tapNumber];
        UIView *singleTapView = [tapNumber view];
        singleTapView.tag = indexPath.row+1;

        UITapGestureRecognizer *tapShou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapShou:)];
        [cell.imageViewShou addGestureRecognizer:tapShou];
        UIView *tapShouTapView = [tapShou view];
        tapShouTapView.tag = indexPath.row+1;

        UITapGestureRecognizer *tapNextPage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNextPage:)];
        [cell.labelContent addGestureRecognizer:tapNextPage];
        UIView *tapNextPageView = [tapNextPage view];
        tapNextPageView.tag = indexPath.row+1;
        //分割线
        CGRect rect = cell.viewLow.frame;
        rect.origin.y = cell.frame.size.height-0.3;
        cell.viewLow.frame = rect;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(void)initWithOneSection:(LSZContentTableViewCell *)cell indexPath:(NSIndexPath *)indexPath
{
    [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:self.imageViewHeader] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    if([self.comeFrame isEqualToString:@"2"]){
        __weak typeof(self) weakSelf = self;
        [cell.imageViewHeader tapGesture:^(UIGestureRecognizer *ges) {
            LSZPersonalInformationPageVC * vc = [[LSZPersonalInformationPageVC alloc]init];
            vc.uid = weakSelf.uid;
            vc.imageViewHeader = weakSelf.imageViewHeader;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
    }
    [cell.imageViewUp sd_setImageWithURL:[NSURL URLWithString:self.imageUrl] placeholderImage:[UIImage imageNamed:@"index_audio_image4"]];
     cell.labelTitle.text = self.strTitle;
    if ([self.strName isEqualToString:@""]||self.strName.length == 0) {
        cell.labelName.text = [NSString stringWithFormat:@"SJ_%@",self.uid];
    }else{
        cell.labelName.text = self.strName;
    }
    cell.labelTime.text = [LSZSpecialPackaging GetThePreviousTimeAndCompareItNow:self.strTime];
    if ([self.comeFrame isEqualToString:@"1"]) {
        cell.labelBigType.hidden = NO;
        cell.labelType.hidden = NO;
        cell.imageViewYuan.hidden = NO;
        cell.butFocusOn.hidden = YES;
    }else{
        cell.labelBigType.hidden = YES;
        cell.labelType.hidden = YES;
        cell.imageViewYuan.hidden = YES;
        cell.butFocusOn.hidden = NO;
        if ([self.is_follow isEqualToString:@"1"]) {
            [cell.butFocusOn setTitle:@"已关注" forState:UIControlStateNormal];
            cell.butFocusOn.backgroundColor =  partialShallow;
            cell.butFocusOn.userInteractionEnabled = NO;
        }else{
            [cell.butFocusOn setTitle:@"+关注" forState:UIControlStateNormal];
            cell.butFocusOn.backgroundColor =  redUIColor;
            cell.butFocusOn.userInteractionEnabled = YES;
        }
        [cell.butFocusOn addTarget:self action:@selector(clickButFocusOnDetaill) forControlEvents:UIControlEventTouchUpInside];
    }
    if ([self.strtype isEqualToString:@"0"]) {
        cell.labelBigType.text = @"祷告";
    }else{
        cell.labelBigType.text = @"见证";
    }
    cell.labelType.text = self.strtypeName;

    CGFloat heightFont;
    CGFloat widthFont;
    if (ScreenWidth == 320) {
        //5
        heightFont = 13.5;
        widthFont = 11.5;
    }else if(ScreenWidth == 375){
        // 6 7
        heightFont = 14;
        widthFont = 12;
    }else {
        //plus
        heightFont = 14.5;
        widthFont = 12.5;
    }
    CGFloat width = [LSZSpecialPackaging caculateWidthOfText:ScreenWidth height:15 font:widthFont :self.strtypeName];
    if (ScreenWidth >375) {
        CGRect rect3 = cell.labelType.frame;
        rect3.size.width = width-10;
        rect3.origin.x = ScreenWidth-width;
        cell.labelType.frame = rect3;
    }else{
        CGRect rect3 = cell.labelType.frame;
        rect3.size.width = width-20;
        rect3.origin.x = ScreenWidth-width-15+20;
        cell.labelType.frame = rect3;
    }


    CGRect rect4 = cell.labelBigType.frame;
    rect4.origin.x =CGRectGetMinX(cell.labelType.frame)-33;
    cell.labelBigType.frame = rect4;

    CGRect rect5 = cell.imageViewYuan.frame;
    rect5.origin.x = CGRectGetMinX(cell.labelBigType.frame)-17;
    cell.imageViewYuan.frame = rect5;

    cell.labelConunt.text = self.strContent;

    CGFloat height = [LSZSpecialPackaging caculateHeightOfText:ScreenWidth-30 height:10000 font:heightFont :self.strContent];
    CGRect rect = cell.labelConunt.frame;
    rect.size.height = height;
    cell.labelConunt.frame = rect;

    CGRect rectBenediction = cell.butBenediction.frame;
    if (ScreenWidth >375) {
        rectBenediction.origin.y = CGRectGetMaxY(cell.labelConunt.frame)+10;
    }else{
        rectBenediction.origin.y = CGRectGetMaxY(cell.labelConunt.frame);
    }
    cell.butBenediction.frame = rectBenediction;

    [cell.butBenediction addTarget:self action:@selector(clickSongZhuFu) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - 关注
-(void)clickButFocusOnDetaill
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }else{
        [LSZRequestData payAttentionToOthers:self.uid Ck:@"0" mode:@"0" :^(BOOL isOk, NSString * str, NSDictionary * dic) {
            if (isOk == YES) {
                [self initWithtring:@"关注成功!"];
                self.is_follow = @"1";
                LSZContentTableViewCell * cell = (LSZContentTableViewCell *)[self.tableViewContentEvaluation cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
                [cell.butFocusOn setTitle:@"已关注" forState:UIControlStateNormal];
                cell.butFocusOn.backgroundColor =  partialShallow;
                cell.butFocusOn.userInteractionEnabled = NO;
                self.prayerAndTestimonyMg.is_follow = @"1";
                self.justClickBlessing = @"2";
            }else{
                [self initWithtring:str];
            }
        }];
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        [self gotoNextPage:indexPath.row];
     }
}
#pragma mark - 进入下一页
-(void)tapNextPage:(UITapGestureRecognizer *)tap
{
    UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)tap;
    [self gotoNextPage: [singleTap view].tag-1];
}
-(void)gotoNextPage :(NSInteger)row
{
    LSZCommentDetailsVC * vc = [[LSZCommentDetailsVC alloc]init];
    LSZResourceEvaluationListMg * manager = nil;
    manager = self.arrayMutPingJia[row];
    vc.strHeaderImageView = manager.publisherHead;
    vc.strName = manager.publisher;
    vc.strZan = manager.praiseNum;
    vc.strTitle = manager.content;
    vc.strTime = manager.publishTime;
    vc.comment_id = manager.id_id;
    vc.id_id = self.id_id;
    vc.publisherId = manager.publisherId;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 送祝福
-(void)clickSongZhuFu
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogInVC];
        return;
    }
    [LSZRequestData UserVersusResourceThumbUp:self.resource_id type:self.type :^(BOOL isOK, NSString * str, NSDictionary * dic) {
        if (isOK == YES) {
            LSZPrayerAndTestimonyMg  * manager = nil;
            manager = self.arrayData[self.lastNumber];
            manager.praiseNum = [NSString  stringWithFormat:@"%zd",([manager.praiseNum integerValue]+1)];
            if ([self.comeFrame isEqualToString:@"1"]) {
                NSString * strid = [NSString stringWithFormat:@"%@_1_%@",shengjing_daogaojianzheng,self.id_id];
                NSInteger num = [manager.praiseNum  integerValue]+1;
                [LSZCacheHandling modifyingParameterOfData:@"lsz_mygd" SmallDirectory:strid key:@"id" value:manager.id_id parameter:@"praiseNum" modifiedValue:[NSString stringWithFormat:@"%zd",num]];
            }else{
                NSString * strid = [NSString stringWithFormat:@"%@_2_%@",shengjing_daogaojianzheng,self.id_id];
                NSInteger num = [manager.praiseNum  integerValue]+1;
                [LSZCacheHandling modifyingParameterOfData:@"lsz_mygd" SmallDirectory:strid key:@"id" value:manager.id_id parameter:@"praiseNum" modifiedValue:[NSString stringWithFormat:@"%zd",num]];
                self.justClickBlessing = @"2";
            }
            [self initClickZan];
        }else{
            [self setStringWarning:str];
        }
    }];
}
-(void)tapShou:(UITapGestureRecognizer *)tap
{
    UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)tap;
    [self initReviewSomePraise:[singleTap view].tag];
}
-(void)tapNumber:(UITapGestureRecognizer *)tap
{
    UITapGestureRecognizer *singleTap = (UITapGestureRecognizer *)tap;
    [self initReviewSomePraise:[singleTap view].tag];
}
#pragma mark - 点赞
-(void)clickZan:(UIButton *)but
{
    [self initReviewSomePraise:but.tag];
}
#pragma mark - 获取用户对评论点赞
-(void)initReviewSomePraise :(NSInteger)Row
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogInVC];
        return;
    }
    LSZResourceEvaluationListMg * manager = nil;
    manager = self.arrayMutPingJia[Row-1];
    [LSZRequestData UsersCommentOnThumbUp:self.type comment_id:manager.id_id :^(BOOL isOK, NSString *str, NSDictionary * dic) {
        if (isOK == YES) {
            LSZResourceEvaluationListMg * manager = nil;
            manager = self.arrayMutPingJia[Row-1];
            NSString * praiseNum = manager.praiseNum;
            NSInteger pnumber = [praiseNum integerValue]+1;
            manager.praiseNum = [NSString stringWithFormat:@"%zd",pnumber];
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:Row-1 inSection:1];
            [self.tableViewContentEvaluation reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            [self setStringWarning:str];
        }
    }];
}
#pragma mark - 进行评价
-(void)initWithUserCommentsOnResources :(NSString *)content
{
    if([[_UserM usercode] isEqualToString:@""]){
        [self gotoLogInVC];
        return;
    }
    [LSZRequestData UserCommentsOnResources:self.resource_id content:content type:self.type :^(BOOL isOK, NSString * Str, NSDictionary * dic) {
        if (isOK == YES) {
            self.uilabel.hidden = NO;
            self.textView.text = @"";
            [self initWithPingJia:self.page];
            [SVProgressHUD showSuccessWithStatus:@"评论成功!"];
            [SVProgressHUD dismissWithDelay:1];
        }else{
            [self setStringWarning:Str];
        }
    }];
}
#pragma mark - 分享
-(void)clickButShare
{
    [self shareShengJingMessageWithImageArray:nil url:@"http://fuyin.app.inping.com/user/download" title:@"祷告见证" contentMessage:@"今日圣经" type:SSDKContentTypeWebPage];
}
-(UITableView *)tableViewContentEvaluation
{
    if (_tableViewContentEvaluation == nil) {
        _tableViewContentEvaluation = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-48) style:UITableViewStyleGrouped];
        if (iPhoneX) {
            _tableViewContentEvaluation.frame = CGRectMake(0, 0, ScreenWidth,ScreenHeight-48-15);
        }else{
            _tableViewContentEvaluation.frame = CGRectMake(0, 0, ScreenWidth,ScreenHeight-48);
        }
        _tableViewContentEvaluation.dataSource = self;
        _tableViewContentEvaluation.delegate = self;
        _tableViewContentEvaluation.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableViewContentEvaluation.estimatedRowHeight =0;
         _tableViewContentEvaluation.estimatedSectionFooterHeight =0;
         _tableViewContentEvaluation.estimatedSectionHeaderHeight =0;
        [self.view addSubview:_tableViewContentEvaluation];
    }
    return _tableViewContentEvaluation;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // 若为UITableViewCellContentView（即点击了tableViewCell），则不截获Touch事件
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    }
    return  YES;
}
-(void)clickSingleTap
{
    [self.view endEditing:YES];
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.height;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    self.tableViewContentEvaluation.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-self.lowView.frame.size.height-height);
    self.lowView.frame = CGRectMake(0, ScreenHeight-self.lowView.frame.size.height-height, ScreenWidth, self.lowView.frame.size.height);
    [UIView commitAnimations];
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    if (iPhoneX) {
        self.tableViewContentEvaluation.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight- self.lowView.frame.size.height-15);
         self.lowView.frame = CGRectMake(0, ScreenHeight-self.lowView.frame.size.height-15, ScreenWidth, self.lowView.frame.size.height);
    }else{
        self.tableViewContentEvaluation.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight- self.lowView.frame.size.height);
        self.lowView.frame = CGRectMake(0, ScreenHeight-self.lowView.frame.size.height, ScreenWidth, self.lowView.frame.size.height);
    }
    [UIView commitAnimations];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
      NSString * strLong = [textView.text stringByReplacingCharactersInRange:range withString:text];
    if (strLong.length == 0) {
        self.uilabel.hidden = NO;
    }else{
        if (strLong.length > 0 &&self.uilabel.hidden == NO) {
            self.uilabel.hidden = YES;
        }
    }
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码  点击发送键
        [self initWithUserCommentsOnResources:strLong];
        [self clickSingleTap];
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    return YES;
}
-(void)gotoLogInVC
{
    if([[_UserM usercode] isEqualToString:@""]){
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AccLogin" bundle:nil];
        UIViewController *controller = [sb instantiateInitialViewController];
        [self.navigationController pushViewController:controller animated:YES];
    }
}
#pragma mark - 点击点赞人
-(void)ClickThumbUpPeopleWithDic:(NSNotification *)notification
{
    NSDictionary * dic = (NSDictionary *)notification.userInfo;
    int number = [dic[@"number"] intValue];
    if(self.zanManager.mutMgArray.count >number){
        LSZThumbUpOrBlessingListForResourcesMg * manager = nil;
        manager = self.zanManager.mutMgArray[number];
        LSZPersonalInformationPageVC * vc = [[LSZPersonalInformationPageVC alloc]init];
        vc.uid =manager.praiserId ;
        vc.imageViewHeader = manager.praiserHead;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        [self setStringWarning:@"请刷新数据,然后重试!"];
    }
}
-(void)dealloc{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
